package com.dys.mvvmstudy.mvvm;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.dys.mvvmstudy.R;
import com.dys.mvvmstudy.databinding.ActivityMvvmBinding;
import com.dys.mvvmstudy.viewmodel.MVVMViewModel;

public class MVVMActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // ActivityMvvmBinding根据布局文件名大写，然后拼接Binding而成
        ActivityMvvmBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_mvvm);
        MVVMViewModel viewModel = new MVVMViewModel(getApplication(),binding);
        // 绑定后，就可以直接在布局文件中直接使用ViewModel
        binding.setViewModel(viewModel);
    }
}
